//
//  TranManager_NavBar.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/7/27.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "TranManager_NavBar.h"

@interface TranManager_NavBar ()

@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) TranNavMenuView *tiHuoView;
@property (nonatomic, strong) TranNavMenuView *fanXiangView;
@property (nonatomic, strong) TranNavMenuView *yunDanView;

@end

@implementation TranManager_NavBar

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        
        self.titleLab = [[UILabel alloc] initWithFrame:CGRectMake(20, StatusBarHeight + 30, ScreenW - 40, 25)];
        self.titleLab.textColor = HexColor(0xffffff);
        self.titleLab.font = BoldFontOfSize(24);
        self.titleLab.text = @"运输管理";
        [self addSubview:self.titleLab];
        
        self.bgView = [[UIView alloc] initWithFrame:CGRectMake(20, self.titleLab.nim_bottom + 20, ScreenW - 40, 100)];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.cornerRadius = 4;
        //设置阴影颜色
        self.bgView.layer.shadowColor = HexColorA(0x2B2C44, 0.1).CGColor;
        //设置阴影的透明度
        self.bgView.layer.shadowOpacity = 1.f;
        //设置阴影的偏移
        self.bgView.layer.shadowOffset = CGSizeMake(0.0f, 4.0f);
        //设置阴影半径
        self.bgView.layer.shadowRadius = 5.0f;
        [self addSubview:self.bgView];
        
        CGFloat viewW = self.bgView.nim_width * 0.5;
        CGFloat viewH = 70;
        self.tiHuoView = [[TranNavMenuView alloc] initWithFrame:CGRectMake(0, 15, viewW, viewH)];
        self.tiHuoView.iconUrl = @"icon_wofayun";
        self.tiHuoView.titleStr = @"我发运的";
        __weak_self;
        self.tiHuoView.clickBlock = ^{
            if (weakself.woFaYunBlock) {
                weakself.woFaYunBlock();
            }
        };
        [self.bgView addSubview:self.tiHuoView];
        
        self.fanXiangView = [[TranNavMenuView alloc] initWithFrame:CGRectMake(self.tiHuoView.nim_right, 15, viewW, viewH)];
        self.fanXiangView.iconUrl = @"icon_woshou";
        self.fanXiangView.titleStr = @"我收的";
        self.fanXiangView.clickBlock = ^{
            if (weakself.woShouBlock) {
                weakself.woShouBlock();
            }
        };
        [self.bgView addSubview:self.fanXiangView];
        
//        self.yunDanView = [[TranNavMenuView alloc] initWithFrame:CGRectMake(self.fanXiangView.nim_right, 15, viewW, viewH)];
//        self.yunDanView.iconUrl = @"Folder";
//        self.yunDanView.titleStr = @"新建运单";
//        self.yunDanView.clickBlock = ^{
//            if (weakself.yunDanBlock) {
//                weakself.yunDanBlock();
//            }
//        };
//        [self.bgView addSubview:self.yunDanView];
    }
    return self;
}

@end

@interface TranNavMenuView ()

@property (nonatomic, strong) UIImageView *iconImgView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIButton *clickBtn;

@end

@implementation TranNavMenuView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {

        self.iconImgView = [[UIImageView alloc] initWithFrame:CGRectMake((frame.size.width - 40) * 0.5, 6, 40, 40)];
        [self addSubview:self.iconImgView];
        
        self.titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, self.iconImgView.nim_bottom + 9, frame.size.width, 15)];
        self.titleLab.textColor = HexColor(0x585974);
        self.titleLab.font = [UIFont systemFontOfSize:14];
        self.titleLab.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.titleLab];
        
        self.clickBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        [self.clickBtn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.clickBtn];
    }
    return self;
}

- (void)btnClick {
    if (self.clickBlock) {
        self.clickBlock();
    }
}

-(void)setIconUrl:(NSString *)iconUrl {
    _iconUrl = iconUrl;
    self.iconImgView.image = [UIImage imageNamed:iconUrl];
}

-(void)setTitleStr:(NSString *)titleStr {
    _titleStr = titleStr;
    self.titleLab.text = titleStr;
}

@end
